package ElectronicSignature;

import sun.misc.BASE64Decoder;

import java.io.FileOutputStream;
import java.io.OutputStream;

/**
 * @Author MJS
 * @Date 2021/10/26 11:00
 * @Description
 */
public class TestSignature {
    public static void main(String[] args) {
        String imgStr="iVBORw0KGgoAAAANSUhEUgAAAfAAAAHwCAYAAABZrD3mAAAZMklEQVR42u3dW3LkurFG4Z7/2Dyn4yc7Tmy3VEUiAeTlWxF88La6VAQy/8Wk6vLnDwAAAICz/N+fP/96c1g5AAAOSTfrYUcBAERN7gAAkDSxAwCI2kHuAACidpA6AICwCR0AQNgOQgcAkLaD0AEAhO0gdAAgbAehAwAI20HmAADSdpA5ABC3w0HmAEDahaRjbcgcAEibGOwXAJC20Lev9hUABLxAt/f2HgAEt6BWH2oEgFAWxBhUQ3YPgNAVuChcW3YNgHAVrChcc3YLgBAVoCBzAOgbmHZIfapRACgQjHYGVYVudwCMC0C7AhehAFAk7OwIXJgCAHEDah6AEBNg0Af6AICwAvSG3gCQOaDsAvSKfgFA3ID+ASB4hA6gnwAMDhurD/2lvwAIFkC/6TVAkAgTRNWalSByAMKDpIrWm9XQiwCEBVEVrTsrkqM3rTogHIQDUS3XX8Tv0Kt6FSBvYUDgh+5MRNRSx/UmckBoan4CTy3wp7U7bc31MUDcGp7AS63JP39+ej3qa4C8NXiyadN6vP93k9/toM8Bja2pCbyswH/6d/pdvwMaWSMT+IX1UHf5+t9KA5p33J5Yj7+vxbe3xlWUi3hA02rY9ALvtua/rcVP56n2ZAKgSTVpuqlz17+ruA5P/ztyZYRVBjQmgQdN71UFvvoBLqrNhT6gITXjVYF33JPfbp/////+pibVrNwANKAGvCbw7vvyrcBX617FyRBgXONZ4TP79nbK7LYGK3cout6lIHJAs2m0InvnLsT6i/XUsmwBNBeO7tfUddkpcBUoZwBNhaW9+ebnCZzAZQ6gkTTRxX1Z2c/pAo9YC7VN4oDmwaM9WpHMpP349gVsPuzGEAFoGE2TfgKdKvC3NU/gJA5oFKSR2JT9Wfn7tzo3WADkDQIv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ie1BABNZC6E1YyaASCUi4eykFYP6gGA8G4W3sJ85l7bXQACftBhD+0hABABYVh/0gYAInc4SBsAyNxB2gAAMncQNwCQucNB2gBA6A7CBgAQuoOwAQBkTtgAAEJ3EDYAgNAdhA0AIHXCBgCA2EkaAEDuRA0AALGTNAAAhE/IAAAAwD7+DfdRTtOKGE42AAAAAElFTkSuQmCC";
        GenerateImage(imgStr);
    }

    public static boolean GenerateImage(String imgStr)
    {   //对字节数组字符串进行Base64解码并生成图片
        if (imgStr == null) //图像数据为空
            return false;
        BASE64Decoder decoder = new BASE64Decoder();
        try
        {
            //Base64解码
            byte[] b = decoder.decodeBuffer(imgStr);
            for(int i=0;i<b.length;++i)
            {
                if(b[i]<0)
                {//调整异常数据
                    b[i]+=256;
                }
            }
            //生成jpeg图片
            String imgFilePath = "D:\\tupian\\tiangong.jpg";//新生成的图片
            OutputStream out = new FileOutputStream(imgFilePath);
            out.write(b);
            out.flush();
            out.close();
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
}
